using System;
using CodePlex.TfsLibrary;
using CodePlex.TfsLibrary.ObjectModel;
using CodePlex.TfsLibrary.Utility;

namespace CodePlex.CodePlexClientLibrary
{
    public class MakePatchConsoleView : IMakePatchView
    {
        string basePath;
        readonly MakePatchPresenter presenter;

        public MakePatchConsoleView(IPatchEngine patchEngine,
                                    IFileSystem fileSystem)
        {
            presenter = new MakePatchPresenter(patchEngine, fileSystem, this);
        }

        public void Run(string directory,
                        string filename)
        {
            basePath = directory;

            presenter.MakePatch(directory, filename);
        }

        public void ShowNothingToPatch()
        {
            Console.WriteLine("Nothing to patch.");
        }

        public void ShowStatus(SourceItem item,
                               SourceItemResult result)
        {
            if (result != SourceItemResult.S_Ok)
                ConsoleUtil.PrintCommandError(item.LocalName, result);
            else
                Console.WriteLine("Processing: {0}", CodePlexClientUtil.GetRelativePath(basePath, item.LocalName));
        }

        public void ShowSyncupWarning()
        {
            ConsoleColor oldColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine();
            Console.WriteLine("WARNING: One or more unversioned or missing items were found.");
            Console.WriteLine("You may want to run the SYNCUP command, then re-create your patch.");
            Console.ForegroundColor = oldColor;
        }
    }
}